package com.example.backend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.backend.entity.Role;
import com.example.backend.entity.UserBooklet;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @author 李月
 * @date 2022/5/2 9:52
 */
@Mapper
public interface UserBookletMapper extends BaseMapper<UserBooklet> {
    /**
     * @param bookletId
     * @return userName
     */
    @Select("SELECT tb_user.nickname from tb_user,tb_user_booklet WHERE tb_user_booklet.booklet_id=#{bookletId} AND tb_user.user_id=tb_user_booklet.user_id")
    String getBookletAuthor(@Param("bookletId") int bookletId);

    /**
     * @param bookletId
     * @return
     */
    @Delete("DELETE FROM tb_user_booklet WHERE tb_user_booklet.booklet_id=#{bookletId}")
    void deleteBooklet(@Param("bookletId") int bookletId);

    /**
     * @param bookletId
     * @return UserBooklet
     */
    @Select("SELECT * FROM tb_user_booklet WHERE tb_user_booklet.booklet_id=#{bookletId}")
    UserBooklet getUserBooklet(@Param("bookletId") int bookletId);
    @Select("SELECT tb_user_booklet.booklet_id FROM tb_user_booklet WHERE tb_user_booklet.user_id=#{userId}")
    int getBookletId(int userId);
    @Select("SELECT * FROM tb_user_booklet WHERE tb_user_booklet.user_id=#{userId}")
    UserBooklet isBooklet(int userId);
}
